package com.huaonline.music.player.server;

import java.io.IOException;

import com.huaonline.music.player.commonutils.LogCommonUtil;
import com.huaonline.music.player.commonutils.ToastCommonUtils;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

public class MusicControlServer extends Service   {
	private MediaPlayer mPlayer=new MediaPlayer();
	private final IMusicControlServer.Stub stub = new IMusicControlServer.Stub() {
		
		public void stop() throws RemoteException {
			ToastCommonUtils.getToastShort("stop", MusicControlServer.this);
		}
		
		public void start() throws RemoteException {
			try {
				mPlayer.prepare();
				mPlayer.start();
			} catch (IllegalStateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
//			ToastCommonUtils.getToastShort("start", MusicControlServer.this);
			
		}
		
		public void prevail() throws RemoteException {
			ToastCommonUtils.getToastShort("prevail", MusicControlServer.this);
		}
		
		public void next() throws RemoteException {
			ToastCommonUtils.getToastShort("next", MusicControlServer.this);
			
		}

		public void setItem(String path) throws RemoteException {
			try {
				System.out.println(path);
				mPlayer.setDataSource(path);
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalStateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	};

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return stub;
	}

	


}
